package observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wcj
 * @Date 2021/6/23 22:09
 * @Version 1.0
 */
public class Subject {

    private String name;

    public String state;

    public List<Observer> observerList = new ArrayList<>();

    public Subject(String name, String state) {
        this.name = name;
        this.state = state;
    }

    public void addObserver(Observer o) {
        observerList.add(o);
    }

    public void removeObserver(Observer o) {
        observerList.remove(o);
    }

    public void notifyObserver() {
        for (Observer observer : observerList) {
            observer.update();
        }
    }
}
